package com.youlu.campus.admin.vote.controller;

import com.alibaba.fastjson.JSON;
import com.youlu.campus.admin.vote.dto.ProvinceSearchDTO;
import com.youlu.campus.admin.vote.dto.VoteOrgOpDTO;
import com.youlu.campus.admin.vote.dto.VoteOrgSaveDTO;
import com.youlu.campus.admin.vote.dto.VoteOrgSearchDTO;
import com.youlu.campus.admin.vote.service.VoteOrgService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : [dengbo]
 * @className : VoteOrgController
 * @description : [组织信息，组织信息api]
 * @createTime : [2022/7/4 09:59]
 */
@Slf4j
@RestController
public class VoteOrgController {

    @Autowired
    private VoteOrgService voteOrgService;

    /**
     * 投票组织列表
     * 组织信息添加/修改接口
     * @param request 投票组织列表
     * @return
     */
    @PostMapping("/vote-org/save")
    public QResult save(@Validated @RequestBody VoteOrgSaveDTO request) {
        log.info("VoteOrgController,save,request param:{}", JSON.toJSONString(request));
        return QResult.success(voteOrgService.save(request));
    }


    /**
     * 投票组织列表
     * 组织信息搜索
     * @param request 投票组织列表
     * @return
     */
    @PostMapping("/vote-org/search")
    public QResult search(@Validated @RequestBody VoteOrgSearchDTO request) {
        log.info("VoteOrgController,search,request param:{}", JSON.toJSONString(request));
        return QResult.success(voteOrgService.search(request));
    }

    /**
     * 省份列表
     * 省份搜索
     * @param request 省份列表
     * @return
     */
    @PostMapping("/province/search")
    public QResult provinceSearch(@Validated @RequestBody ProvinceSearchDTO request) {
        log.info("VoteOrgController,provinceSearch,request param:{}", JSON.toJSONString(request));
        return QResult.success(voteOrgService.provinceSearch(request));
    }

    /**
     * 投票增加/减少
     * 投票增加/减少
     * @param request 投票增加/减少
     * @return
     */
    @PostMapping("/vote-org/op")
    public QResult operation(@Validated @RequestBody VoteOrgOpDTO request) {
        log.info("CourseVideoController,operation,request param:{}", JSON.toJSONString(request));
        boolean re = voteOrgService.operation(request);
        log.info("VoteOrgController,operation,response:{}", re);
        return QResult.success(re);
    }
}